<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
//获取访问入口
$in=dirname(__FILE__);
$in=str_replace(dirname($in),'',$in);
$in=substr($in,1);
if(defined('BY_JYA')){
	$_SESSION['this']=$in;
}else{
	define('IN',$in);
	require '../core/core.php';
	//判断域名是否合法
	if(USER_DOMAIN){
		//开启系统分配独立域名后，不允许非系统分配的独立域名访问客户端页面
		$uniacid=str_replace(DOMAIN_PRE,'',$_SERVER['HTTP_HOST']);
		$uniacid=intval($uniacid);
		if($uniacid){
			//成功获得站点ID，存入$_RQ中备用
			$_RQ['i']=$uniacid;
		}else{
			exit('域名错误(检查是否开启了‘分配独立域名’，但是又不支持泛解析！)');
		}
	}
}
if($_SESSION['this']=='manage'){
	$_SESSION['this']=$in;
}
//判断站点是否关闭
if ($_AR['system']['close']){
	session_destroy();
	echo '站点已关闭，关闭原因：' . $_AR['system']['reason'];
	exit;
}
$_AR['system']['baidu_ak']=$_AR['system']['baidu_ak']?:'w3fWOg3ddn8CFXrFAAkGtdNg5Qy8oBSR';
$_AR['system']['qqmap_ak']=$_AR['system']['qqmap_ak']?:'GGFBZ-HSW35-7KSI4-QSYAM-ZU64O-M2BSN';
//获取站点信息
$uniacid=intval($_RQ['i']);
$_SESSION['fromh5wxapp']=intval($_RQ['fromh5wxapp'])?:$_SESSION['fromh5wxapp'];
$_SESSION['fromh5ttapp']=intval($_RQ['fromh5ttapp'])?:$_SESSION['fromh5ttapp'];
$_SESSION['wxapp_id']=intval($_RQ['wxapp_id'])?:$_SESSION['wxapp_id'];
if($_RQ['fromh5wxapp']){
	$_SESSION['os']='mobile';
}
if(!$uniacid && !$_SESSION['uniacid']){
	$uniacid=1;
}
$_AR['page']=core_setting('site');
if($uniacid || $_SESSION['uniacid']){
	$_SESSION['account']=pdo_get('core_accounts',array('uniacid'=>$uniacid?:$_SESSION['uniacid']),array('openbackpage','baidu_ak','qqmap_ak','stop','no_support','js_support','js_supportimg','title','logo','ewm','isdiy','syscolor'));
	if($_SESSION['account']['baidu_ak']){
		$_AR['system']['baidu_ak']=$_SESSION['account']['baidu_ak'];
	}
	if($_SESSION['account']['qqmap_ak']){
		$_AR['system']['qqmap_ak']=$_SESSION['account']['qqmap_ak'];
	}else{
		$_SESSION['account']['qqmap_ak']=$_AR['system']['qqmap_ak'];
	}
	unset($_SESSION['account']['baidu_ak']);
}
if(($uniacid && $_SESSION['uniacid']!=$uniacid) || !$_SESSION['account']){
	if($uniacid && $_SESSION['uniacid']!=$uniacid){
		$_SESSION['uid']=0;
		$_SESSION['openid']='';
		$_SESSION['uniacid']=$uniacid;
		$_SESSION['isauth_base']=0;
		$_SESSION['isauth_info']=0;
		$_SESSION['fromh5wxapp']=0;
	}
	$kefuset=uni_setting('kefuset');
	if($kefuset){
		$_SESSION['account']=array_merge($_SESSION['account'],$kefuset);
	}
	unset($_SESSION['account']['qrticket']);
	$_SESSION['account']['js_support']=$_SESSION['account']['js_support']?:$_AR['page']['js_support'];
	$_SESSION['account']['js_supportimg']=$_SESSION['account']['js_supportimg']?:$_AR['page']['js_supportimg'];
	$_SESSION['account']['js_supportimg']=tomedia($_SESSION['account']['js_supportimg']);
	//$_SESSION['account']['logo']=$_SESSION['account']['logo']?:$_AR['page']['logo'];
	$_SESSION['account']['logo']=$_SESSION['account']['logo']?tomedia($_SESSION['account']['logo']):tomedia('../core/resource/images/web-logo.jpg');
	//$_SESSION['account']['llogo']=$_SESSION['account']['llogo']?:$_AR['page']['llogo'];
	$_SESSION['account']['llogo']=tomedia($_SESSION['account']['llogo']);
	$_SESSION['account']['ewm']=tomedia($_SESSION['account']['ewm']);
	$_SESSION['account']['openbackpage']=$_SESSION['account']['openbackpage']?:$_AR['page']['openbackpage'];
}
unset($uniacid);
if(!$_SESSION['uniacid'] || empty($_SESSION['account'])){
	exit('找不到指定站点!');
}
//生成token
if(!$_SESSION['token']){
	$_SESSION['token']=random(30);
}
if($_SESSION['account']['stop']>=2 && $_RQ['a']!='stop' && $_RQ['action']!='stop'){
	exi('','error','core/stop/');
	exit;
}
//如果素材要求整理绝对路径
if(intval($_RQ['is_tomedia'])){
	$_SESSION['is_tomedia']=1;
}
//定义是否来自场景体
if($_RQ['current_plugin'] && !preg_match('/\W/',$_RQ['current_plugin'])){
	$_SESSION['current_plugin']=trim($_RQ['current_plugin']);
}
if($_RQ['fromuser'] || intval($_RQ['f'])){
	$_SESSION['fromuser']=intval($_RQ['fromuser'])?:intval($_RQ['f']);
	//来自分享的，如果是场景体首页，刷新菜单
	if($_SESSION['current_plugin'] && $_RQ['plugin']!='core'){
		$is_legao=pdo_getcolumn('core_plugins',array('name'=>$_RQ['plugin']),'is_legao');
		if($is_legao && $_RQ['action']=='index' && (!$_RQ['current_plugin'] || preg_match('/\W/',$_RQ['current_plugin']))){
			$_SESSION['current_plugin']=$_RQ['plugin'];
		}
	}
}
//判断来自第三方小程序；
if($_RQ['t'] && $_RQ['from']=='wxapp'){
	$_SESSION['open_jyapi']=1;
	$_SESSION['container']=$_SESSION['fromapp']=$_SESSION['os']=$_RQ['from'];
	$_RQ['wxgid']=$_RQ['t'];
	if($_RQ['c']=='auth' && $_RQ['a']=='session' && !strcasecmp($_RQ['do'],'openid')){
		$_RQ['op']='login';
		unset($_RQ['c'],$_RQ['a'],$_RQ['do']);
	}
	if($_RQ['c']=='auth' && $_RQ['a']=='session' && $_RQ['do']=='userinfo'){
		$_RQ['p']='core';
		$_RQ['a']='member.login';
		$_RQ['op']='wxapp_login';
		$_RQ['return_info']=2;
		unset($_RQ['c'],$_RQ['a'],$_RQ['do']);
		access(array('plugin'=>'core','action'=>'member.login','query'=>'op=wxapp_login&return_info=2'));
		exit;
	}
}
if($_SESSION['fromh5wxapp'] && $_SESSION['container']=='wxwork'){
	$_SESSION['container']='wechat';
}
if($_SESSION['account']['stop']<=1 || ($_RQ['a']!='stop' && $_RQ['action']!='stop') || ($_RQ['p'] !='core' && $_RQ['plugin'] !='core')){
	$os=in_array($_SESSION['container'],array('ksapp','baiduapp','aliapp','ttapp','wxapp','wechat','wxwork'))?$_SESSION['container']:'common';
	require $os.'.php';
}
if($_SESSION['container']=='alipay'){
	require 'aliapp.php';
}
//获取到openid后，再获取粉丝信息；如果已经获取了，就不再获取
if(($os=='wechat' || $os=='wxwork') && $_SESSION['openid'] && $_SESSION['fast_getinfo']!=1){
	require $os.'.php';
}
if(!$_SESSION['current_plugin'] && $_RQ['plugin']!='core'){
	$is_legao=pdo_getcolumn('core_plugins',array('name'=>$_RQ['plugin']),'is_legao');
	if($is_legao){
		$_SESSION['current_plugin']=$_RQ['plugin'];
	}
}
//第三方插件入口
if(($_RQ['a']=='entry' || $_RQ['c']=='site' || $_RQ['c']=='entry') && $_RQ['m']){
	$_RQ['action']='module';
}
if(($_RQ['a']=='visit' && $_RQ['c']=='utility')){
	exit;
}
if($_RQ['action']=='module'){
	//进入客户小程序
	if($_RQ['from']=='wxapp' || ($_RQ['a']=='wxapp' && $_RQ['c']=='entry')){
		require ROOT_D.'/api/open_jyapi/wxapp.php';
		exit;
	}else{
		require ROOT_D.'/api/open_jyapi/index.php';
		exit;
	}
}
$_AR['page']=core_setting('site');
if(!$_RQ['action']){
	if($_AR['system']['istakeover'] && $_AR['system']['takeoverplugin']){
		$_RQ['plugin'] = $_AR['system']['takeoverplugin'];
		$_RQ['action'] = 'index';
	}else{
		$id=uni_setting('default_mobile_web');
		if($_SESSION['account']['isdiy'] && $id){
			$_RQ['action']='welcome';
		}else{
			$_RQ['action']='home.welcome';
		}
		
	}
}
if(!$_RQ['plugin']){
	$_RQ['plugin']='core';
}
if($_RQ['plugin']=='jy_h5game' && $_RQ['action']=='welcome'){
	access(array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action']));
	exit;
}
if(get_access_setting($_RQ['plugin'],$_RQ['action'])){
  //普通访问，此处整理生成页面
	access(array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action']));
	exit;
}
//访问页面参数
if($_GET['plugin']){
	unset($_GET['plugin']);
}
if($_GET['i']){
	unset($_GET['i']);
}
if($_GET['action']){
	unset($_GET['action']);
}
$query='';
if($_GET){
	$query=http_build_query($_GET);
}
access_log();
$access=array('plugin'=>$_RQ['plugin'],'action'=>$_RQ['action'],'query'=>$query);
$res=cfc('template')->get_customtpl($access);
$html=cfc('tools')->replace($res['search'],$res['html']);
echo $html;
exit;

?>